function Airport(name, locations){
  this.map;
  this.airports;
  this.name = name;
  this.locations = locations;//.transform(geographic, mercator);
  this.runways = [];
  this.defaultRunway = 0;
  this.timetable = new TimeTable(name);
  this.airplanes = [];
  this.beingFlights = new Object();
  var toParis = [];
  var toLondon = [];
  var toBerlin = [];
  this.beingFlights = [toParis, toLondon, toBerlin];
  
  
  this.showName = function(){
    if(this.name != ""){
      return this.name;
    }
    else{
      return alert("Nie nadano nazwy lotniska!");
    }
  }
  
  this.checkBeing = function(time){
    var timeArray = time.split(":");
    var today = new Date();
    var date = new Date(today.getFullYear(), today.getMonth(), today.getDate(),
                        parseInt(timeArray[0]), parseInt(timeArray[1]), today.getSeconds());//parseInt(timeArray[2]));
    var timetable = this.timetable.returnTimeTable();
    var flightTime, startArray, startTime;
    for(var i = 0; i < timetable.length;  i++){
      for(var j = 0; j < timetable[i].length; j++){
        startArray = timetable[i][j].split(":");
        startTime = new Date(today.getFullYear(), today.getMonth(), today.getDate(),
                        startArray[0], startArray[1], today.getSeconds());//startArray[2]);
        switch(i){
          case 0 : { // do Paryza
            switch(this.name){
              case "Londyn" : { // z Londynu
                flightTime = new Date(startTime);
                flightTime.setSeconds(startTime.getSeconds() + (Airplane.defTimeToParis[0] * Airplane.interval / 10));
                break;
              }
              case "Berlin" : { // z Berlina
                flightTime = new Date(startTime);
                flightTime.setSeconds(startTime.getSeconds() + (Airplane.defTimeToParis[1] * Airplane.interval / 10));
                break;
              }
            }
            var flag = false;
            var index;
            for(var k = 0; k < this.beingFlights[0].length; k++){
              if(this.beingFlights[0][k] == timetable[i][j]){
                flag = true; // jeśli lot jest już w tablicy trwających lotów, to
                index = k;
              }
            }
            if(((flightTime - date) / 1000) > Airport.treshhold && (date > startTime)){
              if(!flag){
                this.beingFlights[0].push(timetable[i][j]);
                var airplane = new Airplane(this.name, this.airports[0].name, timetable[i][j], time);
                this.startAirplaneFrom(airplane, this.airports[0]); // sprawdz czy samolot jest pokazany, jesli nie to dodaj i pokaz, airports[0] = do Paryza
              }
            }
            else if(date > startTime){
              if(flag){
                this.beingFlights[0].splice(index, 1);
              }
            }
            break;
          }
          case 1 : { // do Londynu
            switch(this.name){
              case "Paryz" : {
                flightTime = new Date(startTime);
                flightTime.setSeconds(startTime.getSeconds() + (Airplane.defTimeToLondon[0] * Airplane.interval / 10));
                break;
              }
              case "Berlin" : {
                flightTime = new Date(startTime);
                flightTime.setSeconds(startTime.getSeconds() + (Airplane.defTimeToLondon[1] * Airplane.interval / 10));
                break;
              }
            }
            var flag = false;
            var index;
            for(var k = 0; k < this.beingFlights[1].length; k++){
              if(this.beingFlights[1][k] == timetable[i][j]){
                flag = true; // jeśli lot jest już w tablicy trwających lotów, to
                index = k;
              }
            }
            if(((flightTime - date) / 1000) > Airport.treshhold && (date > startTime)){
              if(!flag){
                this.beingFlights[1].push(timetable[i][j]);
                var airplane = new Airplane(this.name, this.airports[1].name, timetable[i][j], time);
                this.startAirplaneFrom(airplane, this.airports[1]);
              }
            }
            else if(date > startTime){
              if(flag){
                this.beingFlights[1].splice(index, 1);
              }
            }
            break;
          }
          case 2 : { // do Berlina
            switch(this.name){
              case "Paryz" : {
                flightTime = new Date(startTime);
                flightTime.setSeconds(startTime.getSeconds() + (Airplane.defTimeToBerlin[0] * Airplane.interval / 10));
                break;
              }
              case "Londyn" : {
                flightTime = new Date(startTime);
                flightTime.setSeconds(startTime.getSeconds() + (Airplane.defTimeToBerlin[1] * Airplane.interval / 10));
                break;
              }
            }
            var flag = false;
            var index;
            for(var k = 0; k < this.beingFlights[2].length; k++){
              if(this.beingFlights[2][k] == timetable[i][j]){
                flag = true; // jeśli lot jest już w tablicy trwających lotów, to
                index = k;
              }
            }
            if(((flightTime - date) / 1000) > Airport.treshhold && (date > startTime)){
              if(!flag){
                this.beingFlights[2].push(timetable[i][j]);
                var airplane = new Airplane(this.name, this.airports[2].name, timetable[i][j], time);
                this.startAirplaneFrom(airplane, this.airports[2]);
              }
            }
            else if(date > startTime){
              if(flag){
                this.beingFlights[2].splice(index, 1);
              }
            }
            break;
          }
        }
      }
    }
  }
  
  this.drawLocations = function(){
    for(var i = 0; i < this.locations.length; i++){
      point = new OpenLayers.Geometry.Point(this.locations[i].lon, this.locations[i].lat);
      feature = new OpenLayers.Feature.Vector(point);
      layers = this.map.getLayersByClass("OpenLayers.Layer.Vector");
      for(var j = 0; j < layers.length; j++){
        layers[j].addFeatures([feature]);
      }
    }
  }
  
  this.addRunways = function(newRunways){
    for(var i = 0; i < newRunways.length; i++){
      this.runways.push(newRunways[i]);
    }
  }
  
  this.startAirplane = function(newAirplane, target){
      var route = this.calculateRoute(target);
      newAirplane.fly(route, false);
      this.airplanes.push(newAirplane);
      switch(newAirplane.to){
        case "Paryz" : {
          this.beingFlights[0].push(newAirplane.startTime);
          break;
        }
        case "Londyn" : {
          this.beingFlights[1].push(newAirplane.startTime);
          break;
        }
        case "Berlin" : {
          this.beingFlights[2].push(newAirplane.startTime);
          break;
        }
      }
  }
  
  this.startAirplaneFrom = function(newAirplane, target){
      var route = this.calculateRoute(target);
      newAirplane.fly(route, true);
      this.airplanes.push(newAirplane);
  }
  
  this.connectWithAirport = function(secondAirport){
    startPoint = new OpenLayers.Geometry.Point(this.location.lon, this.location.lat);
    endPoint = new OpenLayers.Geometry.Point(secondAirport.location.lon, secondAirport.location.lat);
    feature = new OpenLayers.Feature.Vector(
      new OpenLayers.Geometry.LineString([startPoint, endPoint]));
    layers = this.map.getLayersByClass("OpenLayers.Layer.Vector");
    for(var i = 0; i < layers.length; i++){
      layers[i].addFeatures([feature]);
    }
  }
  
  this.connectLocations = function(index, secondLocation){
    startPoint = new OpenLayers.Geometry.Point(this.locations[index].lon, this.locations[index].lat);
    endPoint = new OpenLayers.Geometry.Point(secondLocation.lon, secondLocation.lat);
    feature = new OpenLayers.Feature.Vector(
      new OpenLayers.Geometry.LineString([startPoint, endPoint]));
    layers = this.map.getLayersByClass("OpenLayers.Layer.Vector");
    for(var i = 0; i < layers.length; i++){
      layers[i].addFeatures([feature]);
    }
  }
  
  this.calculateLine = function(secondAirport){
    var x1, x2, y1, y2;
    x1 = this.location.lon;
    y1 = this.location.lat;
    x2 = secondAirport.location.lon;
    y2 = secondAirport.location.lat;
    
    var a, b;
    a = (y1 - y2) / (x1 - x2);
    b = (y2 * x1 - y1) / (x1 - 1);
    
    var array = [a, b];
    return array;
  }
  
  this.calculateRoute = function(secondAirport){
    var route = [];
    var runwaysRoute = this.returnRunwaysRoutes(secondAirport);
    route.push(this.runways[this.defaultRunway].startPoint);
    route.push(this.runways[this.defaultRunway].endPoint);
    route = route.concat(runwaysRoute[0]);
    route.push(runwaysRoute[1]);
    route.push(runwaysRoute[2]);
    route = route.concat(runwaysRoute[3].slice().reverse());
    route.push(secondAirport.runways[secondAirport.defaultRunway].endPoint);
    route.push(secondAirport.runways[secondAirport.defaultRunway].startPoint);
    return route;
  }
  
  this.showTab = function(){
	  var timeTable=this.timetable.returnTimeTable();
	  var logStr;
	  var Tab;
	  switch(this.name){
		  case "Berlin":
			Tab = document.getElementById("berlinTab");
			break;
		 case "Paryz":
			Tab = document.getElementById("parisTab");
			break;
		  case "Londyn":
			Tab = document.getElementById("londonTab");
			break;
	  }
	  for(var i=0; i<timeTable.length; i++){
		for(var j=0; j<timeTable[i].length; j++){
			var newDiv = document.createElement('div');
			switch(i){
				case 0:	logStr= timeTable[i][j]+" do Paryża"; break;
				case 1: logStr= timeTable[i][j]+" do Londynu"; break;
				case 2: logStr= timeTable[i][j]+" do Berlina"; break;
			}
			newDiv.innerHTML = logStr;
			Tab.appendChild(newDiv);
		}		  
	  }
  }
  
  this.returnRunwaysRoutes = function(secondAirport){
    var route = [];
    switch(this.name){
      case "Paryz" : {
        switch(secondAirport.name){
          case "Londyn" : {
            route[0] = Airport.runwaysRoutes[0][0][this.defaultRunway]; // z Paryża do Londynu
            route[1] = this.locations[0];
            route[2] = secondAirport.locations[0];
            route[3] = Airport.runwaysRoutes[1][0][secondAirport.defaultRunway];
            break;
          }
          case "Berlin" : {
            route[0] = Airport.runwaysRoutes[0][1][this.defaultRunway]; // z Paryża do Berlina
            route[1] = this.locations[1];
            route[2] = secondAirport.locations[0];
            route[3] = Airport.runwaysRoutes[2][0][secondAirport.defaultRunway];
            break;
          }
        }
        break;
      }
      case "Londyn" : {
        switch(secondAirport.name){
          case "Paryz" : {
            route[0] = Airport.runwaysRoutes[1][0][this.defaultRunway]; // z Londynu do Paryża
            route[1] = this.locations[0];
            route[2] = secondAirport.locations[0];
            route[3] = Airport.runwaysRoutes[0][0][secondAirport.defaultRunway];
            break;
          }
          case "Berlin" : {
            route[0] = Airport.runwaysRoutes[1][1][this.defaultRunway]; // z Londynu do Berlina
            route[1] = this.locations[1];
            route[2] = secondAirport.locations[1];
            route[3] = Airport.runwaysRoutes[2][1][secondAirport.defaultRunway];
            break;
          }
        }
        break;
      }
      case "Berlin" : {
        switch(secondAirport.name){
          case "Paryz" : {
            route[0] = Airport.runwaysRoutes[2][0][this.defaultRunway]; // z Berlina do Paryza
            route[1] = this.locations[0];
            route[2] = secondAirport.locations[1];
            route[3] = Airport.runwaysRoutes[0][1][secondAirport.defaultRunway];
            break;
          }
          case "Londyn" : {
            route[0] = Airport.runwaysRoutes[2][1][this.defaultRunway]; // z Berlina do Londynu
            route[1] = this.locations[1];
            route[2] = secondAirport.locations[1];
            route[3] = Airport.runwaysRoutes[1][1][secondAirport.defaultRunway];
            break;
          }
        }
        break;
      }
    }
    return route;
  }
}

Airport.treshhold = 10;

Airport.runwaysRoutes = [];
Airport.runwaysRoutes[0] = [ // z Paryza
  [ // do Londynu
    [ // Pas nr 1
      new OpenLayers.LonLat(284758.21183463, 6273648.0961461),
      new OpenLayers.LonLat(283420.56383988, 6274431.5756859),
    ],
    [ // Pas nr 2
      new OpenLayers.LonLat(282885.50464836, 6274374.3479153),
      new OpenLayers.LonLat(282121.13436564, 6274985.8441415),
      new OpenLayers.LonLat(281758.05848135, 6275692.886653),
      new OpenLayers.LonLat(281815.38625256, 6276801.2235629),
      new OpenLayers.LonLat(281719.83996722, 6277489.1568174)
    ]
  ],
  [ // do Berlina
    [ // Pas nr 1
      new OpenLayers.LonLat(284452.46372153, 6273667.2054026),
      new OpenLayers.LonLat(283951.21366348, 6273875.7540778),
      new OpenLayers.LonLat(283588.13777919, 6274191.0568194),
      new OpenLayers.LonLat(283458.782354, 6274374.2479141),
      new OpenLayers.LonLat(283358.82669437, 6274945.8724736),
      new OpenLayers.LonLat(283573.43789641, 6275406.1477957),
      new OpenLayers.LonLat(284089.38783724, 6276036.753279)
    ],
    [ // Pas nr 2
      new OpenLayers.LonLat(283692.87075327, 6274140.1595158),
      new OpenLayers.LonLat(283458.782354, 6274374.2479141),
      new OpenLayers.LonLat(283358.82669437, 6274945.8724736),
      new OpenLayers.LonLat(283573.43789641, 6275406.1477957),
      new OpenLayers.LonLat(284089.38783724, 6276036.753279)
    ]
  ]
];

Airport.runwaysRoutes[1] = [ // z Londynu
  [ // do Paryza
    [ // Pas nr 1
      new OpenLayers.LonLat(-55597.960129435, 6706103.1240392),
      new OpenLayers.LonLat(-56438.767440421, 6705873.8129544),
      new OpenLayers.LonLat(-57069.372923661, 6705281.4259853),
      new OpenLayers.LonLat(-57088.482180728, 6704555.2742167),
      new OpenLayers.LonLat(-56610.750754032, 6703848.2317052),
      new OpenLayers.LonLat(-55980.145270792, 6703523.374335),
      new OpenLayers.LonLat(-55502.413844096, 6702930.9873662),
      new OpenLayers.LonLat(-54986.463903264, 6702071.0707981)
    ],
    [ // Pas nr 2
      new OpenLayers.LonLat(-55559.7416153, 6703829.1224484),
      new OpenLayers.LonLat(-56553.422982829, 6703599.8113635),
      new OpenLayers.LonLat(-58101.272805326, 6703466.0465641),
      new OpenLayers.LonLat(-59094.954172856, 6703962.8872478),
      new OpenLayers.LonLat(-59286.046743535, 6705052.1149007),
      new OpenLayers.LonLat(-58712.769031498, 6705873.8129546),
      new OpenLayers.LonLat(-57642.650635698, 6706007.5777541),
      new OpenLayers.LonLat(-56744.515553508, 6705682.7203839),
      new OpenLayers.LonLat(-56171.237841472, 6704956.5686154),
      new OpenLayers.LonLat(-55884.598985453, 6703981.9965049),
      new OpenLayers.LonLat(-55502.413844096, 6702930.9873662),
      new OpenLayers.LonLat(-54986.463903264, 6702071.0707981)
    ]
  ],
  [ // do Berlina
    [ // Pas nr 1
      new OpenLayers.LonLat(-55443.891744072, 6706396.3317021),
      new OpenLayers.LonLat(-56170.043512651, 6707179.8112419),
      new OpenLayers.LonLat(-56399.354597466, 6708097.0555812),
      new OpenLayers.LonLat(-56170.043512651, 6708937.8628922),
      new OpenLayers.LonLat(-55806.967628362, 6709224.5017485),
      new OpenLayers.LonLat(-55291.017687529, 6709396.4850618)
    ],
    [ // Pas nr 2
      new OpenLayers.LonLat(-54755.958489629, 6704198.7671393),
      new OpenLayers.LonLat(-55310.126944597, 6704733.8263372),
      new OpenLayers.LonLat(-55768.749114226, 6705345.3225634),
      new OpenLayers.LonLat(-56189.152769719, 6706128.8021032),
      new OpenLayers.LonLat(-56456.682368669, 6707141.5927278), 
      new OpenLayers.LonLat(-56399.354597466, 6708097.0555812),
      new OpenLayers.LonLat(-56170.043512651, 6708937.8628922),
      new OpenLayers.LonLat(-55291.017687529, 6709396.4850618)   
    ]
  ]
];

Airport.runwaysRoutes[2] = [ // z Berlina
  [ // do Paryza
    [ // Pas nr 1
      new OpenLayers.LonLat(1510062.8842845, 6871156.3461437),
      new OpenLayers.LonLat(1510865.4730814, 6871022.5813442),
      new OpenLayers.LonLat(1511445.9167648, 6870557.9875322),
      new OpenLayers.LonLat(1511782.7174196, 6870162.6647758),
      new OpenLayers.LonLat(1511942.7574493, 6869602.5246784),
      new OpenLayers.LonLat(1511859.1544479, 6869035.2186088),
      new OpenLayers.LonLat(1511113.8934222, 6868461.9408967)
    ],
    [ // Pas nr 2
      new OpenLayers.LonLat(1510502.3971964, 6870391.9758616),
      new OpenLayers.LonLat(1511285.8767362, 6870487.522147),
      new OpenLayers.LonLat(1511782.7174196, 6870162.6647758),
      new OpenLayers.LonLat(1511942.7574493, 6869602.5246784),
      new OpenLayers.LonLat(1511859.1544479, 6869035.2186088),
      new OpenLayers.LonLat(1511113.8934222, 6868461.9408967)
    ]
  ],
  [ // do Londynu
    [ // Pas nr 1
      new OpenLayers.LonLat(1511400.5322847, 6872303.0015688),
      new OpenLayers.LonLat(1512738.1802794, 6874557.8939028),
      new OpenLayers.LonLat(1512814.6173077, 6877003.8788075),
      new OpenLayers.LonLat(1511859.1544543, 6878609.0564012),
      new OpenLayers.LonLat(1510139.3213182, 6879220.5526273)      
    ],
    [ // Pas nr 2
      new OpenLayers.LonLat(1508228.3956113, 6869895.2351783), 
      new OpenLayers.LonLat(1510024.6657757, 6871080.0091165),
      new OpenLayers.LonLat(1511400.5322847, 6872303.0015688),
      new OpenLayers.LonLat(1512738.1802794, 6874557.8939028),
      new OpenLayers.LonLat(1512814.6173077, 6877003.8788075),
      new OpenLayers.LonLat(1511859.1544543, 6878609.0564012),
      new OpenLayers.LonLat(1510139.3213182, 6879220.5526273)
    ]
  ]
];
